﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ode.Net;
using Ode.Net.Collision;

namespace Painter3D.PhysicalSys
{
    /// <summary>
    /// 物理引擎中的刚体抽象
    /// </summary>
    class RigidBody : Component
    {
        /// <summary>
        /// 刚体
        /// </summary>
        public Body body;

        public RigidBody(Transform transform) : base(transform)
        {
            body = new Body(ODEInterface.world);
            body.Position = ODEInterface.TK2ODE(transform.Pos);
            body.Quaternion = ODEInterface.TK2ODE(transform.Qua);
            body.Moved += Body_Moved;
        }

        private void Body_Moved(object sender, EventArgs e)
        {
            transform.Pos = ODEInterface.ODE2TK(body.Position);
            transform.Qua = ODEInterface.ODE2TK(body.Quaternion);
        }

    }
}
